#include<bits/stdc++.h>
using namespace std;
const int N=5e4+5,M=1e3+5;
int n,m,ans,dp[N][M],p[N],qwq[N][35];
string x,y;
int main()
{
	freopen("neck.in","r",stdin);
	freopen("neck.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>x>>y;
	n=x.size(),m=y.size();
	x=' '+x,y=' '+y;
	p[1]=0;
	for(int i=2;i<=m;++i)
	{
		int now=p[i-1];
		while(now&&y[now+1]!=y[i]) now=p[now];
		if(y[now+1]==y[i]) p[i]=now+1;
		else p[i]=now;
	} 
	for(int i=0;i<m;++i)
		for(int j=0;j<26;++j)
		{
			int now=i;
			while(now&&y[now+1]!=j+'a') now=p[now];
			if(y[now+1]==j+'a') qwq[i][j]=now+1;
			else qwq[i][j]=now;
		}
	dp[0][0]=n;
	for(int i=0;i<n;++i)
		for(int j=0;j<min(i+1,m);++j)
		{
			if(y[j+1]==x[i+1]) 
			{
				dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]);
				dp[i+1][j]=max(dp[i+1][j],dp[i][j]-1);
			}
			else dp[i+1][qwq[j][x[i+1]-'a']]=max(dp[i+1][qwq[j][x[i+1]-'a']],dp[i][j]); 
		}
	for(int i=0;i<m;++i)
	{
		ans=max(ans,dp[n][i]);
	}
	cout<<ans;
	return 0;
 } 
